import os


def r(p):
    f = open(p)
    s = f.read()
    f.close()
    return s


def w(p, s):
    f = open(p, 'w')
    f.write(s)
    f.close()


p = r'C:\Users\Administrator\Downloads\4'
for root, dirs, files in os.walk(p):
    for f in files:
        if f.endswith('.java'):
            p = os.path.join(root, f)
            s = r(p)
            s1 = s.decode('gb2312').encode('utf-8')
            if s1 != s:
                print p
                w(p, s1)
